<template>
	<view class="">

		<u-form-item :label="item.label" :prop="item.value" :required="item.required"
			:borderBottom="item.iscard != 'after' && item.iscard != 'card'"
			:labelPosition="(item.attrs && item.attrs.labelPosition) || 'left'">

			<u--textarea v-if="item.type == 'textarea'" :placeholder="placeholder" v-model="inputValue" border="none"
				:disabled="disabled" @blur="blur" @input="blur"></u--textarea>
			<u--input v-else :placeholder="placeholder" :type="item.type || 'text'" v-model="inputValue" border="none"
				:readonly="disabled" @blur="blur" @change="blur">
				<!-- 建议输入商品名称+价格信息+地区信息 -->
			</u--input>
			<view class="dw" v-if="item.dw">
				{{ item.dw }}
			</view>
		</u-form-item>
	</view>
</template>

<script>
	export default {

		mixins: [uni.$u.mpMixin, uni.$u.mixin],
		props: {
			item: {
				typeof: Object,
				default: () => {
					return {};
				},
			},
			data: {
				typeof: Object,
				default: () => {
					return {};
				},
			},
			value: {
				typeof: [String, Number, Boolean, Array, Object],
				default: () => {
					return "";
				},
			},
		},
		data() {
			return {

				inputValue: "",
			};
		},
		watch: {
			value: {
				handler(n, o) {
					let value = this.value;
					let item = this.item;
					if (!item.value) {
						value = item.defaultValue || "";
					}

					if (item.fl && value && Number(value).div(Number(item.fl)) != 0) {
						value = Number(value).div(Number(item.fl));
					}
					// state.inputValue = value
					this.inputValue = value;
				},
				immediate: true,
				deep: true,
			},
		},
		computed: {
			placeholder() {
				return this.item?.attrs?.placeholder || "请输入内容";
			},
			disabled() {
				this.getParentData("u-form")
				return this.parent.disabled;
			},
		},
		methods: {
			blur() {
				let item = this.item;
				let value = this.inputValue;
				if (item.fl && value && Number(value).div(Number(item.fl)) != 0) {
					value = String(parseInt(Number(value).mul(Number(item.fl))));
				}
				this.$emit("input", value);
				console.log(value, "value");
			},
		},
	};
</script>

<style lang="scss" scoped>
	.dw {
		padding: 0 20rpx;
		color: #2093f5;
	}
</style>